package solved;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;

/*
ID:		liluyan1
LANG:	JAVA
TASK:	stamps
*/
public class stamps {
	public static void main(String[] args) throws IOException {
		BufferedReader f = new BufferedReader(new FileReader("stamps.in"));
		PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(
				"stamps.out")));
		new stamps().solve(f, out);
		out.close();
		System.exit(0);
	}
	
	private void solve(BufferedReader f, PrintWriter out) throws IOException {
		int[] a = read(f, 2);
		int K = a[0];
		int N = a[1];
		a = new int[N];
		String line;
		int i = 0;
		int MAX = 0;
		while ((line = f.readLine()) != null) {
			for (String t : line.split(" ")) {
				if (t.trim().length() == 0) continue;
				a[i] = Integer.parseInt(t);
				MAX = Math.max(MAX, a[i]);
				i++;
			}
		}
		
		boolean[] dp = new boolean[K*MAX+1];
		dp[0] = true;
		int max = 1;
		for (i=0; i<K; i++) {
			for (int j=(i+1)*MAX; j>=max; j--) {
				for (int k=0; k<N; k++) {
					if (j>=a[k]) dp[j] |= dp[j-a[k]];
					if (dp[j]) break;
				}
			}
			
			for (int j=max; j<=(i+1)*MAX; j++) {
				if (dp[j]) {
					max++;
				}
				else {
					break;
				}
			}
		}
		
		out.println(max-1);
	}
	
	public int read(BufferedReader f) throws IOException {
		return Integer.parseInt(f.readLine());
	}
	
	public int[] read(BufferedReader f, int N) throws IOException {
		String[] t = f.readLine().split(" ");
		int[] a = new int[N];
		for (int i=0; i<N; i++) {
			a[i] = Integer.parseInt(t[i]);
		}
		return a;
	}
}
